<template>
  <div class="page">
    <div class="keep-px-title">Safety Guard</div>
    <!-- 登录模块 -->
    <div class="keep-px-login">
      <div class="flex_start row">
        <el-input v-model="loginData.email" placeholder="Email address" />
      </div>
      <div class="flex_start row">
        <el-input
          v-model="loginData.password"
          type="password"
          placeholder="Please input password"
          show-password
        />
      </div>
      <!-- 操作-->
     
      <!-- 登录 -->
      <div class="row flex_center">
        <el-button class="in" @click="loginByPassword"> Link in </el-button>
      </div>
    </div>
    <!-- 提示 -->
    <div class="Toast_fail" v-if="showToast">
      {{ message }}
    </div>
  </div>
</template>

<script>
import API from 'api';
import md5 from "md5";

export default {
  data() {
    return {
      remember: false,
      // 登录模块数据
      loginData: {
        email: "",
        password: "",
        encodePassword: "",
      },
      showToast: false,
      message: "",
    };
  },

  methods: {
    // 切换是否记住用户
    handleChangeRemember() {
      this.remember = !this.remember;
    },
    // 登录
    loginByPassword() {
      if (this.loginData.email == "") {
        this.noticeToast("wrong email")
      }
      if (this.loginData.password == "" && this.loginData.password.length < 6) {
        this.noticeToast("wrong password")
      }
      let param = {
        email: this.loginData.email,
        password: md5(this.loginData.password),
        is_remember: this.remember ? 1 : 0,
      };
      let state = this.$route.query.state
      API.loginByAlexa(param).then(res => {
        console.log('res==', res)
        window.location.href = 'https://pitangui.amazon.com/api/skill/link/M1LU1MM8XA1195?code='+res.code+"&state="+state
      })
      
    },
    initDeviceList() {
      
    },
    noticeToast(msg) {
      this.message = msg;
      this.showToast = true;
      setTimeout(() => {
        this.showToast = false;
      }, 2500);
      return;
    },
  },
  options: {
    styleIsolation: "shared",
  },
};
</script>

<style lang="scss" scoped>
:deep(.el-input__inner) {
  background-color: white!important;
}
.page {
  box-sizing: border-box;
  width: 100%;
  margin: 0 auto;
  overflow: hidden;
}
.keep-px-title {
  font-size: 32px;
  color: #0434a0;
  padding: 70px 0;
  text-align: center;
}

.keep-px-login{
  font-size: 25px;
  color: #333333;
  .row {
    box-sizing: border-box;
    width: 80%;
    margin: 0 auto;
    padding: 10px;
  }
  .in {
    box-sizing: border-box;
    width: 60%;
    height: 50px;
    border-radius: 8px;
    font-size: 32px;
    font-weight: 800;
    color: #fff;
    text-align: center;
    background-color: #0434a0;
    margin-top: 24px;
  }

}

// 提示部分
.Toast_fail {
  position: fixed;
  left: 17vw;
  bottom: 393px;
  width: 50vw;
  padding: 22px 55px;
  color: #fff;
  text-align: center;
  background-color: #666666;
  border-radius: 30px;
}
</style>
